#ifndef _MODE_TEST_H_
#define _MODE_TEST_H_

#include "ornament.h"
#include "singleton.h"

#define MAX_NAME 128
#define MAX_STRING 512


namespace DesignMode{

	typedef enum ERROR_TYPE{
		MODE_TEST_FAIL = 0x01,
		MODE_TEST_RIGHT = 0x02,
		FILE_OPEN_ERROR = 0x04,
		FILE_NOT_EXISTS = 0x08

	};

	typedef enum ModeType{
		Singleton = 0x01,
		Factory = 0x02,
		Proxy = 0x03,
		Adapter = 0x04,
		Ornament = 0x05
	};

	typedef struct Parameter
	{
		char* para_name_;
		char* para_annotation_;
		char* para_value_;
		bool used_;
		Parameter* next;


		Parameter(const char* name_, const char* annotation_, const char* value_){
			para_name_ = new char[MAX_NAME];
			para_annotation_ = new char[MAX_STRING];
			para_value_ = new char[MAX_STRING];
			InitParameter();
			memcpy(para_name_, name_, sizeof(char)*MAX_NAME);
			memcpy(para_annotation_, annotation_, sizeof(char)*MAX_STRING);
			memcpy(para_value_, value_, sizeof(char)*MAX_STRING);
			used_ = false;
			next = nullptr;

		}
		~Parameter()
		{
			DestroyParameterMemory();
		}

		void InitParameter(){
			if (para_name_)
			{
				memset(para_name_, 0, MAX_NAME*sizeof(char));
			}
			if (para_annotation_)
			{
				memset(para_annotation_, 0, MAX_STRING*sizeof(char));
			}
			if (para_value_)
			{
				memset(para_value_, 0, MAX_STRING*sizeof(char));
			}

		}
		void DestroyParameterMemory(){
			if (para_name_)
			{
				delete para_name_;para_name_ = nullptr;
			}
			if (para_annotation_)
			{
				delete para_annotation_; para_annotation_ = nullptr;
			}
			if (para_value_)
			{
				delete para_value_;para_value_ = nullptr;
			}

		}

	};

	class OptParse{
	public:
		OptParse(Parameter* list_head, int para_allocated, int para_used):mPara_list_(list_head),
		nUsedParameter_(para_used), nAllocatedPara_(para_allocated){};
		OptParse(const char* config_file);
		~OptParse();

		//here, we define add/delete/find/change operations
		Parameter* Insert(const char* name, const char* annotation, const char* value);
		bool Register(const char* name);
		
		bool GetParameterValue(const char* name);
		void DestroyParameters();
		void ReleaseOneParameter(const char* name);
		int ParseConfig(const char* config_file);
	protected:
		void TrimBlank(char* in_out_str);
		Parameter* AddNewParameter(const char* name, const char* annoatation, const char* value);
	private:

		Parameter* mPara_list_;
		int nUsedParameter_;
		int nAllocatedPara_;



	};


	int PerformOrnamentMode();
	int PerformAdapterMode();
	int PerformFactoryMode();
	int PerformProxyMode();
	int PerformSingletonMode(SingletonType in_type);
	int StaticSingletonModeTest();
	int TrueSingletonModeTest();

	int DoModePerform(const DesignMode::ModeType& design_mode);

}



#endif

